package com.example.myapplication.lol;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.myapplication.R;
import com.example.myapplication.SettingActivity;
import com.example.myapplication.lol.adapter.ItemAdapter;
import com.example.myapplication.lol.bean.ItemBean;
import com.example.myapplication.lol.ui.FragmentLol1;
import com.example.myapplication.lol.ui.FragmentLol2;
import com.example.myapplication.lol.ui.FragmentLol3;
import com.example.myapplication.lol.ui.FragmentLol4;
import com.example.myapplication.lol.ui.FragmentLol5;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;

import de.hdodenhof.circleimageview.CircleImageView;

public class LolMainActivity extends AppCompatActivity {
    private DrawerLayout rootView;
    private NavigationView navigationView;
    private BottomNavigationView mBottomNavigationView;
    private RecyclerView mRecyclerView;
    private ItemAdapter itemAdapter;
    private LinearLayout settingBtn,lolTitle,lolTitleSearch,setBack;
    private ImageView lolTitleMore,imgOpen;
    private CircleImageView lolTitleImg1,lolTitleImg2;

    private int img [] = {R.drawable.item_1,R.drawable.item_2,R.drawable.item_3,R.drawable.item_4,
            R.drawable.item_5,R.drawable.item_6,R.drawable.item_7};
    private String data [] = {"我的评论","与我相关","我的订单","我的任务","我的收藏","活动中心","信用分"};
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lol_main);
        lolTitleSearch = findViewById(R.id.lol_title_search);
        lolTitleMore = findViewById(R.id.lol_title_more);
        lolTitleImg1 = findViewById(R.id.lol_title_img1);
        lolTitleImg2 = findViewById(R.id.lol_title_img2);
        rootView = findViewById(R.id.drawer_layout);
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        setBack = findViewById(R.id.set_background);
        //点击图片显示侧边栏
        imgOpen = findViewById(R.id.img_open);
        imgOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rootView.openDrawer(navigationView);
            }
        });

        //侧边栏菜单recyclerview实现
        mRecyclerView = findViewById(R.id.item_recyclerView);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(manager);
        itemAdapter = new ItemAdapter();
        mRecyclerView.setAdapter(itemAdapter);
        for (int i = 0; i < 7; i++) {
            ItemBean itemBean = new ItemBean();
            itemBean.setItemText(data[i]);
            itemBean.setItemImg(img[i]);
            itemAdapter.addData(itemBean);
        }

        //点击item提示对应语句
        itemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
                TextView item_text = view.findViewById(R.id.item_text);
                Toast.makeText(LolMainActivity.this,item_text.getText().toString(), Toast.LENGTH_SHORT).show();
            }
        });

        //BottomNavigationView + Fragment实现底部导航栏
        mBottomNavigationView = findViewById(R.id.bottom_nav_view);
        mBottomNavigationView.setSelectedItemId(R.id.tab_news);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_lol_content,new FragmentLol1()).commit();
        //点击切换fragment
        lolTitle = findViewById(R.id.lol_title);
        mBottomNavigationView.setOnNavigationItemSelectedListener(item -> {
            if(item.getItemId()==R.id.tab_user_center || item.getItemId()==R.id.tab_store){
                lolTitleSearch.setVisibility(View.GONE);
                lolTitleImg1.setVisibility(View.GONE);
                lolTitleImg2.setVisibility(View.GONE);
                lolTitleMore.setImageDrawable(getResources().getDrawable(R.drawable.dian_black));
                if (item.getItemId()==R.id.tab_store){
                    lolTitleSearch.setVisibility(View.VISIBLE);
                    lolTitleMore.setImageDrawable(getResources().getDrawable(R.drawable.gouwuche));
                }
            }else {
                lolTitleSearch.setVisibility(View.VISIBLE);
                lolTitleImg1.setVisibility(View.VISIBLE);
                lolTitleImg2.setVisibility(View.VISIBLE);
                lolTitleMore.setImageDrawable(getResources().getDrawable(R.drawable.more2));
            }
            switch (item.getItemId()) {
                case R.id.tab_news:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_lol_content,new FragmentLol1()).commit();
                    break;
                case R.id.tab_circle:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_lol_content,new FragmentLol2()).commit();
                    break;
                case R.id.tab_friend:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_lol_content,new FragmentLol3()).commit();
                    break;
                case R.id.tab_store:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_lol_content,new FragmentLol4()).commit();
                    break;
                case R.id.tab_user_center:
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_lol_content,new FragmentLol5()).commit();
                    break;
            }
            return true;
        });

        settingBtn = findViewById(R.id.tv_setting_btn);
        settingBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(LolMainActivity.this, SettingActivity.class);
                startActivity(intent);
            }
        });

    }
}